package com.mvc.demo.converter;

import com.mvc.demo.bean.User;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
 * @author H
 * @date 2023/1/7
 */
@Component
public class StringToUserConverter implements Converter<String, User> {

    @Override
    public User convert(String source) {
        User user = new User();
        // xiaoming-10
        String[] split = source.split("-");
        String username = split[0];
        Integer age = Integer.parseInt(split[1]);
        user.setUsername(username);
        user.setAge(age);
        return user;
    }

}
